<html>
<head><meta charset="utf-8"><title>miri error: stopping looking for borrow · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html">miri error: stopping looking for borrow</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="154151503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154151503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154151503">(Jan 02 2019 at 01:55)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> Does this Miri error mean I'm doing the bad things?</p>
<div class="codehilite"><pre><span></span>error[E0080]: constant evaluation error: Stopping looking for borrow being accessed (Shr(None)) because of barrier (2013)
</pre></div>



<a name="154151570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154151570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154151570">(Jan 02 2019 at 01:57)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=42581a2568aee144aa129ec2b02ca0ee" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=42581a2568aee144aa129ec2b02ca0ee">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=42581a2568aee144aa129ec2b02ca0ee</a></p>



<a name="154167392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154167392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154167392">(Jan 02 2019 at 10:12)</a>:</h4>
<p>This doesn't have the issue: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=de8998f70e7e8392adead15af45a12b6" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=de8998f70e7e8392adead15af45a12b6">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=de8998f70e7e8392adead15af45a12b6</a></p>



<a name="154167396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154167396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154167396">(Jan 02 2019 at 10:12)</a>:</h4>
<p>Basically in <code>fake_foo_value</code> you are creating a <code>*mut</code> from a <code>*const</code> and reading through it.</p>



<a name="154167460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154167460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154167460">(Jan 02 2019 at 10:14)</a>:</h4>
<p>And that <code>*const</code> is created from a <code>&amp;</code> in <code>FooBorrowed::value</code>.</p>



<a name="154179305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154179305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154179305">(Jan 02 2019 at 15:00)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> </p>
<blockquote>
<p>Does this Miri error mean I'm doing the bad things?</p>
</blockquote>
<p>yes</p>



<a name="154180024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154180024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154180024">(Jan 02 2019 at 15:13)</a>:</h4>
<blockquote>
<p>Basically in <code>fake_foo_value</code> you are creating a <code>*mut</code> from a <code>*const</code> and reading through it.</p>
</blockquote>
<p>reading through it should be fine though, only writing should be a problem</p>



<a name="154180158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154180158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154180158">(Jan 02 2019 at 15:15)</a>:</h4>
<p>or rather, should be a problem if shared references were involved</p>



<a name="154180167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154180167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154180167">(Jan 02 2019 at 15:15)</a>:</h4>
<p><code>*const</code> and <code>*mut</code> dont make any difference</p>



<a name="154180424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154180424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154180424">(Jan 02 2019 at 15:20)</a>:</h4>
<p>note that <code>c_void</code> has size 1, so in general this is a somewhat dangerous pattern. <code>&amp;FooBorrowed</code> actually asserts that there is some dereferencable memory there and gives rustc license to insert spurious reads.</p>



<a name="154180605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154180605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154180605">(Jan 02 2019 at 15:24)</a>:</h4>
<p>oh but you are creating a mutable reference here!</p>



<a name="154180618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154180618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154180618">(Jan 02 2019 at 15:24)</a>:</h4>
<p>that's like writing</p>



<a name="154180634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154180634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154180634">(Jan 02 2019 at 15:24)</a>:</h4>
<p>and you cant write to this pointer because it was obtained from a shared reference (the <code>&amp;self</code> in <code>FooBorrowed::value</code>)</p>



<a name="154191959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154191959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154191959">(Jan 02 2019 at 18:34)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I'd love an improved error message, but I have no concrete suggestion.</p>



<a name="154192191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154192191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154192191">(Jan 02 2019 at 18:39)</a>:</h4>
<blockquote>
<p>creating a *mut from a *const and reading through it.</p>
</blockquote>
<p>‌</p>
<blockquote>
<p>oh but you are creating a mutable reference here!<br>
that's like writing</p>
</blockquote>
<p>Hmm. I didn't actually <em>want</em> a mutable reference there; I just blindly applied the same changes from <code>_new</code> and <code>_free</code>. It's a bit unfortunate that there's no lint for that case, but I can see why it'd be hard to have one.</p>



<a name="154192305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154192305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154192305">(Jan 02 2019 at 18:41)</a>:</h4>
<p>Thank you, <span class="user-mention" data-user-id="120791">@RalfJ</span> and <span class="user-mention" data-user-id="132920">@gnzlbg</span> !</p>



<a name="154192405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154192405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154192405">(Jan 02 2019 at 18:43)</a>:</h4>
<blockquote>
<p>note that <code>c_void</code> has size 1, so in general this is a somewhat dangerous pattern. <code>&amp;FooBorrowed</code> actually asserts that there is some dereferencable memory there and gives rustc license to insert spurious reads.</p>
</blockquote>
<p>In the <a href="https://stackoverflow.com/q/42613798/155423" target="_blank" title="https://stackoverflow.com/q/42613798/155423">broader answer</a>,  I suggest that the better pattern is to use an <code>extern type</code> (once available); would that solve the problem here?</p>



<a name="154194401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154194401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154194401">(Jan 02 2019 at 19:15)</a>:</h4>
<blockquote>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I'd love an improved error message, but I have no concrete suggestion.</p>
</blockquote>
<p>diagnosis could generally need tons of improvements</p>



<a name="154194406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154194406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154194406">(Jan 02 2019 at 19:15)</a>:</h4>
<p>I also have a few ideas</p>



<a name="154194411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154194411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154194411">(Jan 02 2019 at 19:15)</a>:</h4>
<p>but no time to implement them</p>



<a name="154194433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154194433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154194433">(Jan 02 2019 at 19:16)</a>:</h4>
<blockquote>
<p>In the <a href="https://stackoverflow.com/q/42613798/155423" target="_blank" title="https://stackoverflow.com/q/42613798/155423">broader answer</a>,  I suggest that the better pattern is to use an <code>extern type</code> (once available); would that solve the problem here?</p>
</blockquote>
<p>yes</p>



<a name="154196406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154196406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154196406">(Jan 02 2019 at 19:46)</a>:</h4>
<p>Too bad we can't actually change c_void to be an extern type when available</p>



<a name="154197502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154197502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154197502">(Jan 02 2019 at 20:05)</a>:</h4>
<p>yeah</p>



<a name="154201121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154201121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154201121">(Jan 02 2019 at 21:04)</a>:</h4>
<p>Since <code>c_void</code> is 1 byte for LLVM reasons, will the same thing need to happen for extern types...</p>



<a name="154232159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154232159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154232159">(Jan 03 2019 at 10:43)</a>:</h4>
<p>extern types model <code>struct Foo;</code>, while <code>c_void</code> models <code>void</code> in ptr types. so I don't think the problem applies to extern types as well.</p>



<a name="154241888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154241888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154241888">(Jan 03 2019 at 14:20)</a>:</h4>
<blockquote>
<p><code>*const</code> and <code>*mut</code> dont make any difference</p>
</blockquote>
<p>ah yes, the problem is only that the code is calling <code>as_mut</code> instead of <code>as_ref</code>, and that creates a <code>&amp;mut T</code> from a pointer derived from a <code>&amp;</code></p>



<a name="154380500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154380500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154380500">(Jan 04 2019 at 00:55)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I think I'm misunderstanding or missing your point. IIRC, <code>c_void</code> is a one-byte type to enable optimizations in LLVM. Presumably, the same thing will need to be done for extern types. However, I could see if that transformation happens at a lower level (codegen?) and user-written code could not take advantage of it.</p>



<a name="154401675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154401675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154401675">(Jan 04 2019 at 10:46)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span>  AFAIK <code>c_void</code> is 1-byte for the sole reason that <code>*mut c_void</code> should be the same as <code>void*</code></p>



<a name="154454859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154454859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154454859">(Jan 05 2019 at 03:06)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span>  I'm not sure if we are agreeing or disagreeing or other. For context, I'm referring to <a href="https://github.com/rust-lang/libc/blob/22b08f8eedd1ce3eb79e8878613e98dd811907f8/src/unix/mod.rs#L1155-L1165" target="_blank" title="https://github.com/rust-lang/libc/blob/22b08f8eedd1ce3eb79e8878613e98dd811907f8/src/unix/mod.rs#L1155-L1165">this comment</a></p>



<a name="154468684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154468684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154468684">(Jan 05 2019 at 10:42)</a>:</h4>
<p>I disagree with <code>extern type</code> having any of the same issues as <code>c_void</code></p>



<a name="154468688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154468688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154468688">(Jan 05 2019 at 10:42)</a>:</h4>
<p><code>c_void</code> is defined such that <code>*mut c_void</code> can be used in Rust where <code>void*</code> is used in C</p>



<a name="154468702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154468702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154468702">(Jan 05 2019 at 10:43)</a>:</h4>
<p>that's not at all what <code>extern type</code> is for -- so why would any part of that comment be relevant? I am confused.^^ in particular, <code>extern type</code> is going to be unsized in Rust, not have size 1.</p>



<a name="154475865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154475865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154475865">(Jan 05 2019 at 14:51)</a>:</h4>
<blockquote>
<p>that's not at all what <code>extern type</code> is for</p>
</blockquote>
<p>Perhaps this is where my knowledge gap is. I expect to use <code>void *</code> when I want to have an opaque type that I don't know the exact type of. I expect to use an <code>extern type</code> when I have an opaque type with a more concrete/specific type.</p>
<p>I expect to use a pointer to an extern type in <strong>many</strong> of the cases where I currently would use <code>*mut c_void</code>.</p>



<a name="154475910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154475910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154475910">(Jan 05 2019 at 14:52)</a>:</h4>
<p>the usual way (AFAIK) to handle opaque types in C is to use <code>struct Foo;</code> (note the missing field list), and then <code>Foo*</code></p>



<a name="154475918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154475918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154475918">(Jan 05 2019 at 14:53)</a>:</h4>
<p><code>void*</code> isn't for <em>opaque</em> types, it's for <em>unkown</em> types -- basically, for generic code</p>



<a name="154475961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154475961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154475961">(Jan 05 2019 at 14:54)</a>:</h4>
<p>both of these concepts (will) have their counterpart in Rust for FFI, these counterparts being <code>extern { type Foo; }</code> for <code>struct Foo;</code> with <code>*mut Foo</code> for <code>Foo*</code>; and <code>*mut c_void</code> for <code>void*</code>. The Rust side of FFI should then match what the C side of it does (in terms of picking opaque vs unknown types). But my FFI knowledge is very limited so maybe there are reasons to divert here?</p>



<a name="154475963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154475963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154475963">(Jan 05 2019 at 14:54)</a>:</h4>
<p>neither of these (<code>c_void</code> and <code>extern type</code>) have any use outside FFI, AFAIK</p>



<a name="154475986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154475986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154475986">(Jan 05 2019 at 14:55)</a>:</h4>
<p>The usual way (yeah, to model opaque types) <em>now</em> is an empty struct, but that's still a constructable type. An extern type is not. An empty struct is AFAIK not part of the C standard (but it is allowed by both gcc and clang)</p>



<a name="154476029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476029">(Jan 05 2019 at 14:56)</a>:</h4>
<p>the usual way to model <em>opaque</em> types, right? not to model <code>void*</code>?</p>



<a name="154476030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476030">(Jan 05 2019 at 14:56)</a>:</h4>
<p><code>struct Foo;</code> is not an empty struct</p>



<a name="154476031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476031">(Jan 05 2019 at 14:56)</a>:</h4>
<p>its a forward declaration</p>



<a name="154476032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476032">(Jan 05 2019 at 14:56)</a>:</h4>
<p>and AFAIK that's completely standards compliant</p>



<a name="154476033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476033">(Jan 05 2019 at 14:56)</a>:</h4>
<p>so none of what I said above has anything to do with empty structs</p>



<a name="154476034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476034">(Jan 05 2019 at 14:56)</a>:</h4>
<blockquote>
<p><code>struct Foo;</code> is not an empty struct</p>
</blockquote>
<p>Point.</p>



<a name="154476042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476042">(Jan 05 2019 at 14:57)</a>:</h4>
<p>it is in Rust, so I wasn't sure which you meant</p>



<a name="154476043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476043">(Jan 05 2019 at 14:57)</a>:</h4>
<p>fair. I was talking about the C side.</p>



<a name="154476087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476087">(Jan 05 2019 at 14:58)</a>:</h4>
<p>so the current situation is</p>
<p>C: <code>void*</code> &lt;-&gt; Rust: <code>*mut c_void</code><br>
C: <code>sruct Foo;</code> &lt;-&gt; Rust: <a href="https://doc.rust-lang.org/nightly/nomicon/ffi.html#representing-opaque-structs" target="_blank" title="https://doc.rust-lang.org/nightly/nomicon/ffi.html#representing-opaque-structs">https://doc.rust-lang.org/nightly/nomicon/ffi.html#representing-opaque-structs</a></p>



<a name="154476088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476088">(Jan 05 2019 at 14:58)</a>:</h4>
<p>and the intent is, on the Rust side, for <code>extern type</code> to replace <a href="https://doc.rust-lang.org/nightly/nomicon/ffi.html#representing-opaque-structs" target="_blank" title="https://doc.rust-lang.org/nightly/nomicon/ffi.html#representing-opaque-structs">https://doc.rust-lang.org/nightly/nomicon/ffi.html#representing-opaque-structs</a></p>



<a name="154476091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476091">(Jan 05 2019 at 14:59)</a>:</h4>
<p>I still think that people will use an extern type as a reification of a <code>void *</code> when they are "instantiating a generic C function"</p>



<a name="154476100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476100">(Jan 05 2019 at 14:59)</a>:</h4>
<p>although I guess in that case they would want to be able to poke into the struct, so opaque is useless to them</p>



<a name="154476145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476145">(Jan 05 2019 at 15:00)</a>:</h4>
<p>that's a mismatch between the C and Rust side of FFI. it might be valid in some cases (talk to an FFI expert, I am not one^^), and there might be reasons to do that (dito), but the direct translation of the C interface is as I described above</p>



<a name="154476155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476155">(Jan 05 2019 at 15:01)</a>:</h4>
<p>However, my original point was about lower down details, but I still haven't quite picked up what you mean on that.</p>



<a name="154476158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476158">(Jan 05 2019 at 15:01)</a>:</h4>
<p>what's the question that is still open?</p>



<a name="154476201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476201">(Jan 05 2019 at 15:02)</a>:</h4>
<p>Based on the comment I linked, <code>c_void</code> needs to have a size in order to enable optimizations inside of LLVM, but you've said that an extern type is unsized. Does that mean that such optimizations will be precluded from extern types?</p>



<a name="154476211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476211">(Jan 05 2019 at 15:03)</a>:</h4>
<p>Or, will an extern type just be "effectively unsized" in the Rust frontend, but always have a "size" of 1 when generating code so that LLVM can optimize</p>



<a name="154476268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476268">(Jan 05 2019 at 15:05)</a>:</h4>
<p>my reading of that comment (mentioning <code>malloc</code>/<code>free</code>) is that we need this to give our malloc/free the right types on the LLVM side</p>



<a name="154476272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476272">(Jan 05 2019 at 15:05)</a>:</h4>
<p>this is C FFI with functions that have <code>void*</code> in their type, so we must use the proper thing on the Rust side</p>



<a name="154476315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476315">(Jan 05 2019 at 15:06)</a>:</h4>
<p>so I dont think this is a concern for<code>extern type</code>. But I am guessing here, maybe bring this up in the tracking issue?</p>



<a name="154476329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476329">(Jan 05 2019 at 15:07)</a>:</h4>
<p>So you think the optimization is limited to those specific functions? That would be believable. That is, LLVM looks for <code>*i8 malloc(void)</code> and treats it specially, and at one point we did <code>*ZeroSizedType malloc(void)</code> and blew away the optimization</p>



<a name="154476331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476331">(Jan 05 2019 at 15:07)</a>:</h4>
<p>AFAIK our <code>extern type</code> will generate the exact same LLVM types as C's forward declarations, and hence should be optimized the same way</p>



<a name="154476336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476336">(Jan 05 2019 at 15:07)</a>:</h4>
<p>however I have no idea what these types are^^</p>



<a name="154476503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476503">(Jan 05 2019 at 15:13)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">extern</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">nuffin_t</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">myalloc</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">nuffin_t</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">myfree</span><span class="p">(</span><span class="n">_</span>: <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">nuffin_t</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span><span class="nv">%&quot;::nuffin_t&quot;</span> <span class="p">=</span> <span class="k">type</span> <span class="p">{}</span>

<span class="k">declare</span> <span class="nv">%&quot;::nuffin_t&quot;</span><span class="p">*</span> <span class="vg">@myalloc</span><span class="p">()</span> <span class="k">unnamed_addr</span> <span class="vg">#0</span>
<span class="k">declare</span> <span class="kt">void</span> <span class="vg">@myfree</span><span class="p">(</span><span class="nv">%&quot;::nuffin_t&quot;</span><span class="p">*)</span> <span class="k">unnamed_addr</span> <span class="vg">#0</span>
</pre></div>



<a name="154476504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476504">(Jan 05 2019 at 15:13)</a>:</h4>
<p>Now to figure out the C equivalent</p>



<a name="154476673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476673">(Jan 05 2019 at 15:18)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="n">nuffin_t</span><span class="p">;</span>

<span class="k">struct</span> <span class="n">nuffin_t</span> <span class="o">*</span><span class="nf">myalloc</span><span class="p">();</span>
<span class="kt">void</span> <span class="nf">myfree</span><span class="p">(</span><span class="k">struct</span> <span class="n">nuffin_t</span><span class="o">*</span><span class="p">);</span>
</pre></div>


<div class="codehilite"><pre><span></span><span class="nv">%struct.nuffin_t</span> <span class="p">=</span> <span class="k">type</span> <span class="k">opaque</span>

<span class="k">declare</span> <span class="err">dso_local</span> <span class="kt">void</span> <span class="vg">@myfree</span><span class="p">(</span><span class="nv">%struct.nuffin_t</span><span class="p">*)</span> <span class="vg">#1</span>
<span class="k">declare</span> <span class="err">dso_local</span> <span class="nv">%struct.nuffin_t</span><span class="p">*</span> <span class="vg">@myalloc</span><span class="p">(...)</span> <span class="vg">#1</span>
</pre></div>



<a name="154476679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476679">(Jan 05 2019 at 15:18)</a>:</h4>
<p>so that seems like a bug to me.</p>



<a name="154476681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476681">(Jan 05 2019 at 15:18)</a>:</h4>
<p>yeah seems like we are using an empty struct instead of an opaque one, or so?</p>



<a name="154476682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476682">(Jan 05 2019 at 15:18)</a>:</h4>
<p>no idea^^</p>



<a name="154476693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476693">(Jan 05 2019 at 15:19)</a>:</h4>
<p>Cc <span class="user-mention" data-user-id="119009">@eddyb</span></p>



<a name="154476695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476695">(Jan 05 2019 at 15:19)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> haha, check it; right at the top in the tracking issue:</p>
<blockquote>
<p>In std's source, it is mentioned that LLVM expects i8* for C's void*.<br>
We'd need to continue to hack this for the two c_voids in std and libc.<br>
But perhaps this should be done across-the-board for all extern types?<br>
Somebody should check what Clang does.</p>
</blockquote>



<a name="154476698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476698">(Jan 05 2019 at 15:19)</a>:</h4>
<p>;)</p>



<a name="154476701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri%20error%3A%20stopping%20looking%20for%20borrow/near/154476701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/miri.20error.3A.20stopping.20looking.20for.20borrow.html#154476701">(Jan 05 2019 at 15:20)</a>:</h4>
<p>well you just checked what clang does</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>